<?php
namespace app\index\controller;

use my\Test;
use think\Db;

class Index
{
    public function index()
    {
		// return config('var_jsonp_handler');
		var_dump(config('queue'));
		// return json(['code' => 0, 'message' => 'hello']);
		// $test = new Test();
		// $test -> sayHello();die;
        // echo 'this is thinkphp5';
        // htmlspecialchars(string)
        // array_count_values(input)
    }


    public function sort_arr($arr) {
    	$count = count($arr);
    	for($i = 0; $i < $count - 1; $i++) {
    		for($j = $i + 1; $j < $count; $j++) {
    			if($arr[$i] < $arr[$j]) {
    				$tmp = $arr[$i];
    				$arr[$i] = $arr[$j];
    				$arr[$j] = $tmp;
    			}
    		}
    	}
    	return $arr;
	}
	
	public function sql() {
		// $res = Db::query('select * from user where id=?',[1]);
		// $res = Db::execute('insert into user(name, age) values(?, ?)', ['王五', 45]);
		// $res = db('user') -> where('id', 1) -> column('id','name');
		// p($res);
		$sql = 'select * from user where id=1';
		$time = time();
		Db::listen(function($sql, $time, $explain){
			// 记录SQL
			echo $sql. ' ['.$time.'s]';
			// 查看性能分析结果
			dump($explain);
		});
	}

	public function model_test() {
		$user = model('User')::get('2');
		p($user -> toArray());die;
		$user -> name = 'thinkphp5';
		$user -> save();
	}


}
